package zzh.com.kangkenuo.newutlis;


import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe;

/**
 * @author
 * @Name: EventbusHelper
 * @Description: ${todo}
 * @date
 * @time
 * @copyright 做一个简单的对eventBus的封装, 后续添加log这些
 */
public class EventbusHelper {
    /**
     * TimeEvent 不适用这个接口,避免有太多log
     *
     * @param event
     */
    public static void post(Object event) {
        String _msgType = (String) ((MsgEvent) event).getMsgType();
        EventBus.getDefault().post(event);
    }

    /**
     * 刷新数据
     *
     * @param event
     */
    public static void refreshData(Object event) {
        String _msgType = (String) ((MsgEvent) event).getMsgType();
        EventBus.getDefault().post(event);
    }

    @Subscribe
    public static void register(Object subscriber) {
        if (!EventBus.getDefault().isRegistered(subscriber)) {
            EventBus.getDefault().register(subscriber);
        }
    }

    public static void unregister(Object subscriber) {
        if (EventBus.getDefault().isRegistered(subscriber)) {
            EventBus.getDefault().unregister(subscriber);
        }
    }

}
